package com.cookiesoft.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cookiesoft.common.annotation.Log;
import com.cookiesoft.common.core.controller.BaseController;
import com.cookiesoft.common.core.domain.AjaxResult;
import com.cookiesoft.common.enums.BusinessType;
import com.cookiesoft.order.domain.ZhenOrders;
import com.cookiesoft.order.service.IZhenOrdersService;
import com.cookiesoft.common.utils.poi.ExcelUtil;
import com.cookiesoft.common.core.page.TableDataInfo;

/**
 * 订单，存储用户订单信息Controller
 *
 * @author anc
 * @date 2024-11-06
 */
@CrossOrigin
@RestController
@RequestMapping("/order/orders" )
public class ZhenOrdersController extends BaseController {
    @Autowired
    private IZhenOrdersService zhenOrdersService;

/**
 * 查询订单，存储用户订单信息列表
 */
@PreAuthorize("@ss.hasPermi('order:orders:list')" )
@GetMapping("/list" )
    public TableDataInfo list(ZhenOrders zhenOrders) {
        startPage();
        List<ZhenOrders> list = zhenOrdersService.selectZhenOrdersList(zhenOrders);
        return getDataTable(list);
    }

    /**
     * 导出订单，存储用户订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:orders:export')" )
    @Log(title = "订单，存储用户订单信息" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, ZhenOrders zhenOrders) {
        List<ZhenOrders> list = zhenOrdersService.selectZhenOrdersList(zhenOrders);
        ExcelUtil<ZhenOrders> util = new ExcelUtil<ZhenOrders>(ZhenOrders. class);
        util.exportExcel(response, list, "订单，存储用户订单信息数据" );
    }

    /**
     * 获取订单，存储用户订单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:orders:query')" )
    @GetMapping(value = "/{orderId}" )
    public AjaxResult getInfo(@PathVariable("orderId" ) Long orderId) {
        return success(zhenOrdersService.selectZhenOrdersByOrderId(orderId));
    }

    /**
     * 新增订单，存储用户订单信息
     */
    @PreAuthorize("@ss.hasPermi('order:orders:add')" )
    @Log(title = "订单，存储用户订单信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhenOrders zhenOrders) {
        return toAjax(zhenOrdersService.insertZhenOrders(zhenOrders));
    }

    /**
     * 修改订单，存储用户订单信息
     */
    @PreAuthorize("@ss.hasPermi('order:orders:edit')" )
    @Log(title = "订单，存储用户订单信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhenOrders zhenOrders) {
        return toAjax(zhenOrdersService.updateZhenOrders(zhenOrders));
    }

    /**
     * 删除订单，存储用户订单信息
     */
    @PreAuthorize("@ss.hasPermi('order:orders:remove')" )
    @Log(title = "订单，存储用户订单信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}" )
    public AjaxResult remove(@PathVariable Long[] orderIds) {
        return toAjax(zhenOrdersService.deleteZhenOrdersByOrderIds(orderIds));
    }
}
